<?php
$uses_api = $bank_info['Bank']['uses_api'];
?>
<div id="left_nav" class="span4">
    <div id="nav_group" class="inner_shadow">
        <ul>
            <?php
            $link_name = "Search";
            $link_name_p = "Search Student";
            if($uses_api == 'Yes'){
                $link_name = "Home";
                $link_name_p = "Home";
            }
            ?>
            <li>
                <a href="<?php echo $this->Html->url(array('action' => 'index')); ?>"><i class="icon-home icon-2x"></i></a>
                        <span>
                            <a href="<?php echo $this->Html->url(array('action' => 'index')); ?>"> <?php echo $link_name; ?></a>
                            <p><?php echo $link_name_p; ?></p>
                        </span>
            </li>
        </ul>
        <?php
        $uses_api = $bank_info['Bank']['uses_api'];
        $auth_user = $this->Session->read('loginData');
        $user_level = $auth_user['user_level'];
        if ($user_level != 'Normal') {
            ?>

            <?php
            if ($user_level == 'Admin') {
                echo $this->element('bank/nav_admin');
            } elseif ($user_level == 'Supervisor') {
                echo $this->element('bank/nav_branch_sup');
            }
            ?>

        <?php
        }
        else{
            ?>

        <?php
        }
        ?>
    </div>
</div>

<div class="span8"  style="padding:10px; background-color: #fff; min-height: 480px;">
    <?php
    $error = false;
    if($this->Session->check('process_error')){
        if($this->Session->read('process_error') == 'yes'){
            $error = true;
        }
        $controller->Session->delete('process_error');
    }
    ?>
    <?php
    $flash_msg = $this->Session->read('Message');
    if(isset($flash_msg['flash'])){
        ?>
        <div id="loginmsg" style="">
            <?php
            if($error){
                echo $this->Message->msg('Profile Update',$this->Session->flash(),'error',true);
            }
            else{
                echo $this->Message->msg('Profile Update',$this->Session->flash(),'success',true);
            }
            ?>
        </div>
    <?php
    }
    ?>
    <?php echo $this->Form->create('BankUser', array('id' => 'form', 'class' => 'form form-horizontal', 'inputDefaults' => array('label' => false,'div' => false)));?>
    <fieldset>
        <legend>Edit your profile information, <?php echo $authuser['fname'];?> ! </legend>
        <div class="control-group">
            <label class="control-label" for="username">* Username:</label>
            <div class="controls">
                <?php $authuser['username'] ;?>
                <?php echo $this->Form->input('username', array('id'=>'username', 'class' => 'input-block-level', 'value'=>$authuser['username'], 'required'=>'required','div' => false, 'label' => false,)); ?>
            </div>
        </div>

        <div class="control-group cheque_row">
            <label class="control-label" for="password">New Password:</label>
            <div class="controls">
                <?php echo $this->Form->input('password', array('type'=>'password','id'=>'password', 'class' => 'input-block-level', 'placeholder'=>'Password','div' => false, 'label' => false,)); ?>
            </div>
        </div>
        <div class="control-group cheque_row">
            <label class="control-label" for="password">Retype Password:</label>
            <div class="controls">
                <?php echo $this->Form->input('re_password', array('type'=>'password','id'=>'re_password', 'class' => 'input-block-level', 'placeholder'=>'Password','div' => false, 'label' => false,)); ?>
            </div>
        </div>

        <div class="control-group cheque_row">
            <label class="control-label" for="cellphone">* First Name:</label>
            <div class="controls">
                <?php echo $this->Form->input('fname', array('id'=>'fname', 'class' => 'input-block-level', 'value'=>$authuser['fname'],'required'=>'required','div' => false, 'label' => false,)); ?>
            </div>
        </div>

        <div class="control-group cheque_row">
            <label class="control-label" for="cellphone">Middle Name:</label>
            <div class="controls">
                <?php echo $this->Form->input('mname', array('id'=>'mname', 'class' => 'input-block-level', 'value'=>$authuser['mname'],'div' => false, 'label' => false,)); ?>
            </div>
        </div>

        <div class="control-group cheque_row">
            <label class="control-label" for="cellphone">* Last Name:</label>
            <div class="controls">
                <?php echo $this->Form->input('lname', array('id'=>'lname', 'class' => 'input-block-level', 'value'=>$authuser['lname'],'required'=>'required','div' => false, 'label' => false,)); ?>
            </div>
        </div>

        <div class="control-group">
            <label class="control-label">&nbsp;</label>
            <div class="controls">
                <button type="submit" id="update_btn" class="btn btn-primary">Update Info</button>
                <button type="reset"  id="reset_btn" class="btn">Cancel</button>
            </div>
        </div>

        <?php echo $this->Form->input('id', array('id'=>'id', 'value'=>$authuser['id'],'div' => false, 'label' => false,)); ?>
    </fieldset>
    <?php echo $this->Form->end();?>
</div>


<script type="text/javascript">
    $(document).ready(function () {
        $("#cellphone").mask("999-999999999");

        $("#form").submit(function(){
            validate_pass();
            return false;
        });

        function validate_pass(){
            var pass = $("#password").val();
            var re_pass = $("#re_password").val();
            if(pass || re_pass){
                //check for min 8 char
                if(pass.length < 8){
                    alert('Passwords must be more than 8 characters long.');
                    return;
                }
                //Thus it contian a number
                var matches = pass.match(/\d+/g);
                if (matches == null) {
                    alert('Passwords must contain a number.');
                    return;
                }
                //Thus it contian a capital letter
                var matches = pass.match(/[A-Z]/);
                if (matches == null) {
                    alert('Passwords must contain a capital letter');
                    return;
                }
                //Are pass the same
                if(pass != re_pass){
                    alert('Passwords Mismatch.');
                    return;
                }
            }
            else{
                // alert('empty')
            }

            $("#form").submit();
        }
    });
</script>